﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Ession;
using System.Xml.Serialization;
using System.Net.Sockets;
using System.Diagnostics;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace ConsoleApplication1
{
    class MyClass
    {
        public string S { get; set; }
        public int I { get; set; }
    }
    class Program
    {
        static void Print(int[] p)
        {
            foreach (var i in p)
            {
                Console.Write(i);

            }
            Console.WriteLine();
        }
        static int n = 5, r = 5;
        static bool[] used = new bool[n];
        static int[] E = new int[] { 0, 1, 2, 3, 4 };

        static int[] P = new int[5];
        static void PrintStack(Stack<Object> s)
        {
            var o = s.Pop();
            while (o != null)
            {
                Console.WriteLine((int)o);
                o = s.Pop();
            }
        }
        private Stack<Object> stack = new Stack<Object>();

        /**  
         * 获得指定数组从指定开始的指定数量的数据组合<br>  
         *   
         * @param arr 指定的数组  
         * @param begin 开始位置  
         * @param num 获得的数量  
         */
        public void getSequence(Object[] arr, int begin, int num)
        {
            if (num == 0)
            {
                PrintStack(stack); // 找到一个结果   
            }
            else
            {
                // 循环每个可用的元素   
                for (int i = begin; i < arr.Length; i++)
                {
                    // 当前位置数据放入结果堆栈   
                    stack.Push(arr[i]);
                    // 将当前数据与起始位置数据交换   
                    swap(arr, begin, i);
                    // 从下一个位置查找其余的组合   
                    getSequence(arr, begin + 1, num - 1);
                    // 交换回来   
                    swap(arr, begin, i);
                    // 去除当前数据   
                    stack.Pop();
                }
            }
        }

        /**  
         * 交换2个数组的元素  
         *   
         * @param arr 数组  
         * @param from 位置1  
         * @param to 位置2  
         */
        public static void swap(Object[] arr, int from, int to)
        {
            if (from == to)
            {
                return;
            }
            Object tmp = arr[from];
            arr[from] = arr[to];
            arr[to] = tmp;
        }

        static void Main(string[] args)
        {
            //Program t = new Program();
            //object[] arr = new object[] { 1, 2, 3 };
            //// 循环获得每个长度的排列组合   
            //for (int num = 1; num <= arr.Length; num++)
            //{
            //    t.getSequence(arr, 0, num);
            //}
            //List<string> l = new List<string>();
            //for (int i = 0; i < 10; i++)
            //{
            //    for (int j = 0; j < 10; j++)
            //    {
            //        for (int k = 0; k < 10; k++)
            //        {
            //            var s = string.Format("{0:0}{1:0}{2:0}", i, j,k);
            //            if (!l.Contains(s))
            //            {
            //                l.Add(s);
            //            } 
            //        }

            //        ;

            //    }

            //}
            //Console.WriteLine(l.Count);

            //foreach (var VARIABLE in l)
            //{
            //    Console.WriteLine(VARIABLE);
            //}
            //Ession.DigitPwdGenerator dpg = new DigitPwdGenerator(4, 6);
            //dpg.GenerateUsingNextLower(new StreamWriter(@"F:\test.txt"));
            // dpg.GenerateAllLowerDigitNumber(new StreamWriter(@"F:\test2.txt"));

            // ServicePointManager.DefaultConnectionLimit = 100;
            //ThreadPool.SetMaxThreads(300, 300);
            //Uri u = new Uri("http://www.baidu.com");
            //int s, t;
            //for (int i = 0; i < 300; i++)
            //{
            //    ThreadPool.QueueUserWorkItem(
            //  sf =>
            //  {

            //      WebClientTimeout wc=new WebClientTimeout();

            //      try
            //      {
            //          results[(int)sf] = wc.DownloadString(u);
            //      }
            //      catch (Exception ex)
            //      {
            //          Console.WriteLine((int)sf + ex.ToString());

            //      }

            //  }, i);
            //}
            //Console.WriteLine("press s to exit.");
            //string index;
            //while ((index = Console.ReadLine()) != "s")
            //{
            //    Console.WriteLine(results.Where(sdd => !string.IsNullOrEmpty(sdd)).ToList().Count);
            //}
            //List<int> l = new List<int>() { 2, 3, 2, 5, 3 };
            //XmlSerializer xmlSerializer = new XmlSerializer(l.GetType());
            //xmlSerializer.Serialize(new FileStream(@"fd.xml", FileMode.OpenOrCreate), l);
            //VSClient.exe	5712	TCP	ession-pc	21280	121.14.223.3	1267	ESTABLISHED										

            //  VSClient.exe	5712	TCP	ession-pc	21280		1267	ESTABLISHED										
            //   var s = Ession.Disconnecter.Connections(Disconnecter.State.Established);
            //foreach (var s1 in s)
            //{
            //    if (s1.Contains("121.14"))
            //    {
            //        Disconnecter.CloseConnection(s1);
            //    }
            //}
            //     Disconnecter.CloseLocalPort(65173);


            //    Console.WriteLine(client.Connected);
            //     client.Close();
            //  TcpListener tcp=new TcpListener(new IPEndPoint(IPAddress.Parse("192.168.1.104"),21280));

            //Console.WriteLine(client.Connected);


            //   Process p = new Process();
            //   p.StartInfo.FileName = "cmd.exe";
            //   p.StartInfo.UseShellExecute = false;
            //   p.StartInfo.RedirectStandardInput = true;
            //   p.StartInfo.RedirectStandardOutput = true;
            //   p.StartInfo.RedirectStandardError = true;
            //   p.StartInfo.CreateNoWindow = true;
            //   p.Start();
            //   //查看本机端口占用情况
            ////   p.StandardInput.WriteLine(" netstat -no | findstr 6112 ");
            //   p.StandardInput.WriteLine(" netstat -no  ");

            //   p.StandardInput.WriteLine("exit");
            //   //
            //   StreamReader reader = p.StandardOutput;//截取输出流
            //   string strAllInfo = "";
            //   string strLocalInfo = "";
            //   string strLine = reader.ReadLine();//每次读取一行
            //   int i = 0;
            //   while (!reader.EndOfStream)
            //   {
            //       strAllInfo += strLine + "\r\n";

            //       i++;

            //       if (i < 9)//去掉之前相关信息
            //       {
            //           /*
            //           Microsoft Windows [版本 5.2.3790]
            //           (C) 版权所有 1985-2003 Microsoft Corp.

            //           E:\Documents and Settings\Administrator>netstat -an

            //           Active Connections

            //             Proto  Local Address          Foreign Address        State
            //           */
            //       }
            //       else
            //       {
            //           if (strLine.Trim().Length > 0)
            //           {
            //               strLine = strLine.Trim();
            //               Regex r = new Regex(@"\s+");
            //               string[] strArr = r.Split(strLine);
            //               strLocalInfo += strArr[1] + "|\r\n";
            //           }
            //       }
            //       strLine = reader.ReadLine();//再下一行          
            //   }
            //   p.WaitForExit();//等待程序执行完退出进程
            //   p.Close();//关闭进程
            //   reader.Close();//关闭流

            //   Console.WriteLine(strAllInfo);



            //Ession.HttpRequestSender hs = new HttpRequestSender();
            //hs.PostData("http://175yo.com/login.php",
            //            "jumpurl=http%3A%2F%2F175yo.com%2Fthread.php%3Ffid-45.html&step=2&cktime=31536000&pwuser=gar08&pwpwd=kookkk&lgt=0&question=0&customquest=&answer=",
            //            Encoding.GetEncoding("GB2312"), "Set-Cookie", f => {
            //                                                                   Console.WriteLine(f);
            //                                                                   return true;
            //            }

            //    );
            //List<string> data = new List<string>();
            //for (int i = 1; i < 8575; i++)
            //{
            //    string d = string.Format("http://175yo.com/member.php?orderway=&asc=&page={0}", i);
            //    data.Add(d);
            //}

            //    File.WriteAllLines(@"F:\dd.txt", data);

            // string fuck = "{\"月份\":\"08\",\"姓名\":\"高志星\",\"岗位工资\": \"1700\"}";
            //var   s= JsonConvert.DeserializeObject<Dictionary<string,string>>(fuck);
            // Console.WriteLine(s.GetType().ToString());
            //List<string> pcodes = new List<string>();
            //for (int i = 0; i < 13000; i++)
            //{
            //    pcodes.Add(string.Format("{0:00000}", i));
            //}

            //for (int i = 0; i < 50; i++)
            //{
            //    Console.WriteLine(pcodes[i]);
            //}


            //            string data = @"{column:[{Count:'27',ColumnName:'月份'},{Count:'27',ColumnName:'姓名'},{Count:'27',ColumnName:'岗位工资级别'},{Count:'27',ColumnName:'岗位工资'},{Count:'27',ColumnName:'基础工资'},
            //{Count:'27',ColumnName:'工龄工资'},{Count:'27',ColumnName:'餐贴'},{Count:'27',ColumnName:'物业补贴'},{Count:'27',ColumnName:'住房补贴'},{Count:'27',ColumnName:'保留工资'},{Count:'27',ColumnName:'地区补贴'},
            //{Count:'27',ColumnName:'维修放行津贴'},{Count:'27',ColumnName:'夜班津贴'},{Count:'27',ColumnName:'其他工资'},{Count:'27',ColumnName:'加班费'},{Count:'27',ColumnName:'补发工资'},{Count:'27',ColumnName:'补扣工资'},{Count:'27',ColumnName:'应发小计'},{Count:'27',ColumnName:'考勤扣款'},{Count:'27',ColumnName:'公积金扣款'},{Count:'27',ColumnName:'社会保险扣款'},
            //
            //{Count:'27',ColumnName:'个人所得税'},{Count:'27',ColumnName:'总务扣款'},{Count:'27',ColumnName:'其他扣款'},{Count:'27',ColumnName:'企业年金个人缴费'},{Count:'27',ColumnName:'实发小计'},
            //{Count:'27',ColumnName:'备注'}],totalPorperty:'4',root:[{月份:'03',姓名:'高志星',岗位工资级别:'19G-04',岗位工资:'3385',基础工资:'650',工龄工资:'40',餐贴:'300',物业补贴:'200',住房补贴:'605',保留工资:'',地区补贴:'0',维修放行津贴:'',夜班津贴:'0',其他工资:'',加班费:'443.27',补发工资:'',补扣工资:'',应发小计:'5623.27',考勤扣款:'0',公积金扣款:'219',社会保险扣款:'211.58',个人所得税:'64.27',
            //
            //总务扣款:'',其他扣款:'',企业年金个人缴费:'',实发小计:'5128.42',备注:''},{月份:'02',姓名:'高志星',岗位工资级别:'19G-04',岗位工资:'3385',基础工资:'650',工龄工资:'40',餐贴:'300',物业补贴:'200',住房补贴:'605',保留工资:'',地区补贴:'0',维修放行津贴:'',夜班津贴:'',其他工资:'',加班费:'0',补发工资:'',补扣工资:'',应发小计:'5180',考勤扣款:'0',公积金扣款:'219',社会保险扣款:'211.58',个人所得税:'37.48',总务扣款:'',其他扣款:'',企业年金个人缴费:'',实发小计:'4711.94',备注:'正式定岗'},{月份:'01',姓名:'高志星',岗位工资级别:'11G-09',岗位工资:'1910',基础工资:'650',工龄工资:'40',餐贴:'300',物业补贴:'200',住房补贴:'384',保留工资:'',地区补贴:'0',维修放行津贴:'',夜班津贴:'',其他工资:'',加班费:'0',补发工资:'',补扣工资:'',应发小计:'3484',考勤扣款:'',公积金扣款:'219',社会保险扣款:'211.58',个人所得税:'0',总务扣款:'',其他扣款:'',企业年金个人缴费:'',实发小计:'3053.42',备注:''},{月份:'总计',姓名:'',岗位工资级别:'',岗位工资:'8680',基础工资:'1950',工龄工资:'120',餐贴:'900',物业补贴:'600',住房补贴:'1594',保留工资:'',地区补贴:'',维修放行津贴:'',夜班津贴:'',其他工资:'',加班费:'443.27',补发工资:'',补扣工资:'',应发小计:'14287.27',考勤扣款:'',公积金扣款:'657',社会保险扣款:'634.74',个人所得税:'101.75',总务扣款:'',其他扣款:'',企业年金个人缴费:'',实发小计:'12893.78',备注:''}],succsee:true}";

            //            var d = JsonConvert.DeserializeObject<JObject>(data);
            //            //var q = from p in d.Properties() where p.Name=="root"
            //            //        select p ;
            //            //foreach (var p in q)
            //            //{
            //            //    Console.WriteLine(p.Value.ToString());
            //            //}
            //            //  Console.WriteLine(q.First().Value);

            //            var s = d.Property("root").Value[0].ToObject<SalaryQuery.SalaryMonth>();



            //            Console.WriteLine(s.住房补贴);

            //            var ttt = d["root"];

            //            foreach (var  vv in ttt.Values()  )
            //            {
            //                Console.WriteLine(vv);
            //            }
            //List<string> pwds = new List<string>();

            //var sss = new string[] { " # " };
            //string[] data = File.ReadAllLines(@"F:\CSDN-中文IT社区-600万\www.csdn.net.sql");

            //for (int i = 0; i < data.Length; i++)
            //{
            //    data[i] = data[i].Split(sss, StringSplitOptions.RemoveEmptyEntries)[1];

            //}
            //pwds.AddRange(data);

            //Console.WriteLine(pwds.Count);

            //var query = pwds.GroupBy(s => s).OrderByDescending(g => g.Count()).Where(gg => gg.Count() > 10);

            //Console.WriteLine("组数:" + query.Count());
            //int groupIndex = 0;
            //foreach (var group in query)
            //{
            //    File.AppendAllText(@"top pwds.txt",group.Key + ":" + group.Count()+"\r\n"); 
              
            //}



          //  Console.WriteLine(string.Format("{0}{1}{1}", 1, 2,3));

            // MyClass  m=new MyClass(){S = "fuck",I = 122};

            //var m2 = Cloner<MyClass>.Copy(m);
            //Console.WriteLine(m2.I);

//            EssTcpServer server=new EssTcpServer();
//            server.NewClientConnected += new Action<string, string>(server_NewClientConnected);
//            server.OnMessageReceived += new EssTcpServer.MessageReceive(server_OnMessageReceived);
//            server.Start(10000);
//
//            TcpClientEss client=new TcpClientEss();
//            client.Connect(IPAddress.Parse("192.168.90.93"),10000);
//
//            client.SendMessage("fuck");
            


            Console.WriteLine("press any key to exit.");
            Console.ReadKey();

        }

        static void server_OnMessageReceived(EssTcpServer sender, string Data)
        {
            Console.WriteLine(Data);
        }

        static void server_NewClientConnected(string arg1, string arg2)
        {
            Console.WriteLine(arg1);
        }
        static string[] results = new string[300];
        private static int errorCount;
        private static int succCount;
        static int CanCount;
        static void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            if (e.Cancelled)
            {
                CanCount++;

            }
            else
            {
                if (e.Error != null)
                {
                    errorCount++;
                }
                else
                {
                    succCount++;
                }
            }



        }
    }
}
